package org.sky.wall.visual.adapter

import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import org.sky.wall.visual.databinding.ItemBinding
import org.sky.wall.visual.pojo.Item
import org.sky.wall.visual.ui.SettingActivity

/**
 *Create by Xianban
 *2024/1/16 17:18
 */

class ListAdapter(private val context: Context,private val list:MutableList<Int>):
	RecyclerView.Adapter<ListAdapter.ViewHolder>() {
	inner class ViewHolder(private val bin:ItemBinding):RecyclerView.ViewHolder(bin.root) {
			fun bind(item: Int){
			//	bin.image.setImageResource(item)
				Glide.with(context)
					.load(item)
					.into(bin.image)
				bin.root.setOnClickListener {
					Intent(context,SettingActivity::class.java).also {
						it.putExtra("url",item)
						context.startActivity(it)
					}
					
				}
			}
	}
	
	override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
		val binding = ItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
		return ViewHolder(binding)
	}
	
	override fun getItemCount(): Int=list.size
	
	override fun onBindViewHolder(holder: ViewHolder, position: Int) {
		holder.bind(list[position])
	}
}